<template>
  <a-layout>
    <a-layout-header class="header">
      <h2 class="logo">UNI-APP</h2>
      <a-menu
        v-model:selectedKeys="selectedKeys1"
        theme="dark"
        mode="horizontal"
        :style="{ lineHeight: '64px' }"
        @click="setMenu1"
      >
        <a-menu-item :key="index" v-for="(item, index) in menu">{{
          item.name
        }}</a-menu-item>
      </a-menu>
    </a-layout-header>
    <a-layout>
      <a-layout-sider width="200">
        <a-menu
          theme="dark"
          v-model:selectedKeys="selectedKeys2"
          v-model:openKeys="openKeys"
          mode="inline"
          :style="{ height: '100%', borderRight: 0 }"
        >
          <a-sub-menu :key="index" v-for="(item, index) in setMenu2">
            <template #title>
              <span>
                <user-outlined />
                {{ item.title }}
              </span>
            </template>
            <a-menu-item
              @click="setMenu3(index2)"
              :key="index2"
              v-for="(item2, index2) in item.children"
              ><router-link :to="item2.path">{{
                item2.name
              }}</router-link></a-menu-item
            >
          </a-sub-menu>
        </a-menu>
      </a-layout-sider>
      <a-layout style="padding: 0 24px 24px">
        <a-layout-content
          :style="{
            background: '#fff',
            padding: '24px',
            margin: 0,
            minHeight: '280px',
          }"
        >
          Content
        </a-layout-content>
      </a-layout>
    </a-layout>
  </a-layout>
</template>

<script lang='ts'>
import { defineComponent, ref, reactive, toRefs, computed } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
export default defineComponent({
  setup() {
    let store = useStore();
    let router = useRouter();

    let selectedKeys1 = reactive<number[]>([0]);
    let selectedKeys2 = reactive<number[]>([0]);
    let openKeys = reactive<number[]>([0]);

    let menu = store.state.userInfo.menu;

    let setMenu1 = (key: any) => {
      selectedKeys1[0] = key.key;
    };

    let setMenu2 = computed(() => {
      return menu[selectedKeys1[0]].children;
    });

    let setMenu3 = (index: number) => {
      selectedKeys1[0] = index;
    };

    return {
      selectedKeys1,
      selectedKeys2,
      collapsed: ref<boolean>(false),
      openKeys,
      menu,
      setMenu1,
      setMenu2,
      setMenu3,
    };
  },
});
</script>

<style scoped >
.ant-layout {
  height: 100%;
}
.header {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
h2 {
  color: #fff;
}

#components-layout-demo-top-side-2 .logo {
  float: left;
  width: 120px;
  height: 31px;
  margin: 16px 24px 16px 0;
  background: rgba(255, 255, 255, 0.3);
}

.ant-row-rtl #components-layout-demo-top-side-2 .logo {
  float: right;
  margin: 16px 0 16px 24px;
}

.site-layout-background {
  background: #fff;
}
</style>
